# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: unittest\loader.py
"""Loading unittests."""
import os, re, sys, traceback, types, functools, warnings
from fnmatch import fnmatch
from . import case, suite, util
__unittest = True
VALID_MODULE_NAME = re.compile('[_a-z]\\w*\\.py$', re.IGNORECASE)

class _FailedTest(case.TestCase):
    _testMethodName = None

    def __init__(self, method_name, exception):
        self._exception = exception
        super(_FailedTest, self).__init__(method_name)

    def __getattr__(self, name):
        if name != self._testMethodName:
            return super(_FailedTest, self).__getattr__(name)
        else:

            def testFailure():
                raise self._exception

            return testFailure


def _make_failed_import_test(name, suiteClass):
    message = 'Failed to import test module: %s\n%s' % (
     name, traceback.format_exc())
    return _make_failed_test(name, ImportError(message), suiteClass, message)


def _make_failed_load_tests(name, exception, suiteClass):
    message = 'Failed to call load_tests:\n%s' % (traceback.format_exc(),)
    return _make_failed_test(name, exception, suiteClass, message)


def _make_failed_test(methodname, exception, suiteClass, message):
    test = _FailedTest(methodname, exception)
    return (
     suiteClass((test,)), message)


def _make_skipped_test(methodname, exception, suiteClass):

    @case.skip(str(exception))
    def testSkipped(self):
        pass

    attrs = {methodname: testSkipped}
    TestClass = type('ModuleSkipped', (case.TestCase,), attrs)
    return suiteClass((TestClass(methodname),))


def _jython_aware_splitext(path):
    if path.lower().endswith('$py.class'):
        return path[:-9]
    else:
        return os.path.splitext(path)[0]


class TestLoader(object):
    """
    This class is responsible for loading tests according to various criteria
    and returning them wrapped in a TestSuite
    """
    testMethodPrefix = 'test'
    sortTestMethodsUsing = staticmethod(util.three_way_cmp)
    suiteClass = suite.TestSuite
    _top_level_dir = None

    def __init__(self):
        super(TestLoader, self).__init__()
        self.errors = []
        self._loading_packages = set()

    def loadTestsFromTestCase(self, testCaseClass):
        """Return a suite of all test cases contained in testCaseClass"""
        if issubclass(testCaseClass, suite.TestSuite):
            raise TypeError('Test cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?')
        testCaseNames = self.getTestCaseNames(testCaseClass)
        if not testCaseNames:
            if hasattr(testCaseClass, 'runTest'):
                testCaseNames = [
                 'runTest']
        loaded_suite = self.suiteClass(map(testCaseClass, testCaseNames))
        return loaded_suite

    def loadTestsFromModule(self, module, *args, pattern=None**kws):
        """Return a suite of all test cases contained in the given module"""
        if len(args) > 0 or 'use_load_tests' in kws:
            warnings.warn('use_load_tests is deprecated and ignored', DeprecationWarning)
            kws.pop('use_load_tests', None)
        if len(args) > 1:
            complaint = len(args) + 1
            raise TypeError(('loadTestsFromModule() takes 1 positional argument but {} were given').format(complaint))
        if len(kws) != 0:
            complaint = sorted(kws)[0]
            raise TypeError(("loadTestsFromModule() got an unexpected keyword argument '{}'").format(complaint))
        tests = []
        for name in dir(module):
            obj = getattr(module, name)
            if isinstance(obj, type):
                if issubclass(obj, case.TestCase):
                    tests.append(self.loadTestsFromTestCase(obj))

        load_tests = getattr(module, 'load_tests', None)
        tests = self.suiteClass(tests)
        if load_tests is not None:
            try:
                return load_tests(self, tests, pattern)
            except Exception as e:
                error_case, error_message = _make_failed_load_tests(module.__name__, e, self.suiteClass)
                self.errors.append(error_message)
                return error_case

            return tests

    def loadTestsFromName(self, name, module=None):
        """Return a suite of all test cases given a string specifier.
        
        The name may resolve either to a module, a test case class, a
        test method within a test case class, or a callable object which
        returns a TestCase or TestSuite instance.
        
        The method optionally resolves the names relative to a given module.
        """
        parts = name.split('.')
        error_case, error_message = (None, None)
        if module is None:
            parts_copy = parts[:]
            while parts_copy:
                try:
                    module_name = ('.').join(parts_copy)
                    module = __import__(module_name)
                    break
                except ImportError:
                    next_attribute = parts_copy.pop()
                    error_case, error_message = _make_failed_import_test(next_attribute, self.suiteClass)
                    if not parts_copy:
                        self.errors.append(error_message)
                        return error_case

            parts = parts[1:]
        obj = module
        for part in parts:
            try:
                parent, obj = obj, getattr(obj, part)
            except AttributeError as e:
                if getattr(obj, '__path__', None) is not None:
                    if error_case is not None:
                        self.errors.append(error_message)
                        return error_case
                    error_case, error_message = _make_failed_test(part, e, self.suiteClass, 'Failed to access attribute:\n%s' % (
                     traceback.format_exc(),))
                    self.errors.append(error_message)
                    return error_case

        if isinstance(obj, types.ModuleType):
            return self.loadTestsFromModule(obj)
        if isinstance(obj, type):
            if issubclass(obj, case.TestCase):
                return self.loadTestsFromTestCase(obj)
            if isinstance(obj, types.FunctionType):
                if isinstance(parent, type):
                    pass
        if issubclass(parent, case.TestCase):
            name = parts[-1]
            inst = parent(name)
            if not isinstance(getattr(inst, name), types.FunctionType):
                return self.suiteClass([inst])
        else:
            if isinstance(obj, suite.TestSuite):
                return obj
            if callable(obj):
                test = obj()
                if isinstance(test, suite.TestSuite):
                    return test
                if isinstance(test, case.TestCase):
                    return self.suiteClass([test])
                raise TypeError('calling %s returned %s, not a test' % (
                 obj, test))
            else:
                raise TypeError("don't know how to make test from: %s" % obj)

    def loadTestsFromNames(self, names, module=None):
        """Return a suite of all test cases found using the given sequence
        of string specifiers. See 'loadTestsFromName()'.
        """
        suites = [self.loadTestsFromName(name, module) for name in names]
        return self.suiteClass(suites)

    def getTestCaseNames(self, testCaseClass):
        """Return a sorted sequence of method names found within testCaseClass
        """

        def isTestMethod(attrname, testCaseClass=testCaseClass, prefix=self.testMethodPrefix):
            return attrname.startswith(prefix) and callable(getattr(testCaseClass, attrname))

        testFnNames = list(filter(isTestMethod, dir(testCaseClass)))
        if self.sortTestMethodsUsing:
            testFnNames.sort(key=functools.cmp_to_key(self.sortTestMethodsUsing))
        return testFnNames

    def discover(self, start_dir, pattern='test*.py', top_level_dir=None):
        """Find and return all test modules from the specified start
        directory, recursing into subdirectories to find them and return all
        tests found within them. Only test files that match the pattern will
        be loaded. (Using shell style pattern matching.)
        
        All test modules must be importable from the top level of the project.
        If the start directory is not the top level directory then the top
        level directory must be specified separately.
        
        If a test package name (directory with '__init__.py') matches the
        pattern then the package will be checked for a 'load_tests' function. If
        this exists then it will be called with (loader, tests, pattern) unless
        the package has already had load_tests called from the same discovery
        invocation, in which case the package module object is not scanned for
        tests - this ensures that when a package uses discover to further
        discover child tests that infinite recursion does not happen.
        
        If load_tests exists then discovery does *not* recurse into the package,
        load_tests is responsible for loading all tests in the package.
        
        The pattern is deliberately not stored as a loader attribute so that
        packages can continue discovery themselves. top_level_dir is stored so
        load_tests does not need to pass this argument in to loader.discover().
        
        Paths are sorted before being imported to ensure reproducible execution
        order even on filesystems with non-alphabetical ordering like ext3/4.
        """
        set_implicit_top = False
        if top_level_dir is None:
            if self._top_level_dir is not None:
                top_level_dir = self._top_level_dir
            if top_level_dir is None:
                set_implicit_top = True
                top_level_dir = start_dir
        top_level_dir = os.path.abspath(top_level_dir)
        if top_level_dir not in sys.path:
            sys.path.insert(0, top_level_dir)
        self._top_level_dir = top_level_dir
        is_not_importable = False
        is_namespace = False
        tests = []
        if os.path.isdir(os.path.abspath(start_dir)):
            start_dir = os.path.abspath(start_dir)
            if start_dir != top_level_dir:
                is_not_importable = not os.path.isfile(os.path.join(start_dir, '__init__.py'))
        else:
            try:
                __import__(start_dir)
            except ImportError:
                is_not_importable = True

            the_module = sys.modules[start_dir]
            top_part = start_dir.split('.')[0]
        try:
            start_dir = os.path.abspath(os.path.dirname(the_module.__file__))
        except AttributeError:
            try:
                spec = the_module.__spec__
            except AttributeError:
                spec = None

            if spec:
                pass
            if spec.loader is None:
                if spec.submodule_search_locations is not None:
                    is_namespace = True
                    for path in the_module.__path__:
                        if not set_implicit_top:
                            if not path.startswith(top_level_dir):
                                continue
                            self._top_level_dir = path.split(the_module.__name__.replace('.', os.path.sep))[0]
                            tests.extend(self._find_tests(path, pattern,
                              namespace=True))

                if the_module.__name__ in sys.builtin_module_names:
                    raise TypeError('Can not use builtin modules as dotted module names') from None
                else:
                    raise TypeError(("don't know how to discover from {!r}").format(the_module)) from None

        if set_implicit_top:
            if not is_namespace:
                self._top_level_dir = self._get_directory_containing_module(top_part)
                sys.path.remove(top_level_dir)
            else:
                sys.path.remove(top_level_dir)
            if is_not_importable:
                raise ImportError('Start directory is not importable: %r' % start_dir)
            if not is_namespace:
                tests = list(self._find_tests(start_dir, pattern))
            return self.suiteClass(tests)

    def _get_directory_containing_module(self, module_name):
        module = sys.modules[module_name]
        full_path = os.path.abspath(module.__file__)
        if os.path.basename(full_path).lower().startswith('__init__.py'):
            return os.path.dirname(os.path.dirname(full_path))
        else:
            return os.path.dirname(full_path)

    def _get_name_from_path(self, path):
        if path == self._top_level_dir:
            return '.'
        else:
            path = _jython_aware_splitext(os.path.normpath(path))
            _relpath = os.path.relpath(path, self._top_level_dir)
            if not not os.path.isabs(_relpath):
                raise AssertionError('Path must be within the project')
            if not not _relpath.startswith('..'):
                raise AssertionError('Path must be within the project')
            name = _relpath.replace(os.path.sep, '.')
            return name

    def _get_module_from_name(self, name):
        __import__(name)
        return sys.modules[name]

    def _match_path(self, path, full_path, pattern):
        return fnmatch(path, pattern)

    def _find_tests(self, start_dir, pattern, namespace=False):
        """Used by discovery. Yields test suites it loads."""
        name = self._get_name_from_path(start_dir)
        if name != '.':
            if name not in self._loading_packages:
                tests, should_recurse = self._find_test_path(start_dir, pattern, namespace)
                if tests is not None:
                    yield tests
                if not should_recurse:
                    return
                paths = sorted(os.listdir(start_dir))
                for path in paths:
                    full_path = os.path.join(start_dir, path)
                    tests, should_recurse = self._find_test_path(full_path, pattern, namespace)
                    if tests is not None:
                        yield tests
                    if should_recurse:
                        name = self._get_name_from_path(full_path)
                        self._loading_packages.add(name)
                        try:
                            yield from self._find_tests(full_path, pattern, namespace)
                        finally:
                            self._loading_packages.discard(name)

    def _find_test_path--- This code section failed: ---

 418       0  LOAD_GLOBAL              'os'
           2  LOAD_ATTR                'path'
           4  LOAD_ATTR                'basename'
           6  LOAD_FAST                'full_path'
           8  CALL_FUNCTION_1       1  ''
          10  STORE_FAST               'basename'

 419      12  LOAD_GLOBAL              'os'
          14  LOAD_ATTR                'path'
          16  LOAD_ATTR                'isfile'
          18  LOAD_FAST                'full_path'
          20  CALL_FUNCTION_1       1  ''
          22  POP_JUMP_IF_FALSE   326  'to 326'

 420      26  LOAD_GLOBAL              'VALID_MODULE_NAME'
          28  LOAD_ATTR                'match'
          30  LOAD_FAST                'basename'
          32  CALL_FUNCTION_1       1  ''
          34  POP_JUMP_IF_TRUE     40  'to 40'

 422      36  LOAD_CONST               (None, False)
          38  RETURN_END_IF    

 423      40  LOAD_FAST                'self'
          42  LOAD_ATTR                '_match_path'
          44  LOAD_FAST                'basename'
          46  LOAD_FAST                'full_path'
          48  LOAD_FAST                'pattern'
          50  CALL_FUNCTION_3       3  ''
          52  POP_JUMP_IF_TRUE     58  'to 58'

 424      54  LOAD_CONST               (None, False)
          56  RETURN_END_IF    

 426      58  LOAD_FAST                'self'
          60  LOAD_ATTR                '_get_name_from_path'
          62  LOAD_FAST                'full_path'
          64  CALL_FUNCTION_1       1  ''
          66  STORE_FAST               'name'

 427      68  SETUP_EXCEPT         84  'to 84'

 428      70  LOAD_FAST                'self'
          72  LOAD_ATTR                '_get_module_from_name'
          74  LOAD_FAST                'name'
          76  CALL_FUNCTION_1       1  ''
          78  STORE_FAST               'module'
          80  POP_BLOCK        
          82  JUMP_FORWARD        172  'to 172'
        84_0  COME_FROM_EXCEPT     68  '68'

 429      84  DUP_TOP          
          86  LOAD_GLOBAL              'case'
          88  LOAD_ATTR                'SkipTest'
          90  COMPARE_OP               'exception-match'
          92  POP_JUMP_IF_FALSE   130  'to 130'
          94  POP_TOP          
          96  STORE_FAST               'e'
          98  POP_TOP          
         100  SETUP_FINALLY       120  'to 120'

 430     102  LOAD_GLOBAL              '_make_skipped_test'
         104  LOAD_FAST                'name'
         106  LOAD_FAST                'e'
         108  LOAD_FAST                'self'
         110  LOAD_ATTR                'suiteClass'
         112  CALL_FUNCTION_3       3  ''
         114  LOAD_CONST            0  False
         116  BUILD_TUPLE_2         2  ''
         118  RETURN_VALUE     
       120_0  COME_FROM_FINALLY   100  '100'
         120  LOAD_CONST               None
         122  STORE_FAST               'e'
         124  DELETE_FAST              'e'
         126  END_FINALLY      
         128  JUMP_FORWARD        322  'to 322'

 431     130  POP_TOP          
         132  POP_TOP          
         134  POP_TOP          

 433     136  LOAD_GLOBAL              '_make_failed_import_test'
         138  LOAD_FAST                'name'
         140  LOAD_FAST                'self'
         142  LOAD_ATTR                'suiteClass'
         144  CALL_FUNCTION_2       2  ''
         146  UNPACK_SEQUENCE_2     2  ''
         148  STORE_FAST               'error_case'
         150  STORE_FAST               'error_message'

 434     152  LOAD_FAST                'self'
         154  LOAD_ATTR                'errors'
         156  LOAD_ATTR                'append'
         158  LOAD_FAST                'error_message'
         160  CALL_FUNCTION_1       1  ''
         162  POP_TOP          

 435     164  LOAD_FAST                'error_case'
         166  LOAD_CONST            0  False
         168  BUILD_TUPLE_2         2  ''
         170  RETURN_VALUE     
       172_0  COME_FROM            82  '82'

 437     172  LOAD_GLOBAL              'os'
         174  LOAD_ATTR                'path'
         176  LOAD_ATTR                'abspath'

 438     178  LOAD_GLOBAL              'getattr'
         180  LOAD_FAST                'module'
         182  LOAD_CONST               '__file__'
         184  LOAD_FAST                'full_path'
         186  CALL_FUNCTION_3       3  ''
         188  CALL_FUNCTION_1       1  ''
         190  STORE_FAST               'mod_file'

 439     192  LOAD_GLOBAL              '_jython_aware_splitext'

 440     194  LOAD_GLOBAL              'os'
         196  LOAD_ATTR                'path'
         198  LOAD_ATTR                'realpath'
         200  LOAD_FAST                'mod_file'
         202  CALL_FUNCTION_1       1  ''
         204  CALL_FUNCTION_1       1  ''
         206  STORE_FAST               'realpath'

 441     208  LOAD_GLOBAL              '_jython_aware_splitext'

 442     210  LOAD_GLOBAL              'os'
         212  LOAD_ATTR                'path'
         214  LOAD_ATTR                'realpath'
         216  LOAD_FAST                'full_path'
         218  CALL_FUNCTION_1       1  ''
         220  CALL_FUNCTION_1       1  ''
         222  STORE_FAST               'fullpath_noext'

 443     224  LOAD_FAST                'realpath'
         226  LOAD_ATTR                'lower'
         228  CALL_FUNCTION_0       0  ''
         230  LOAD_FAST                'fullpath_noext'
         232  LOAD_ATTR                'lower'
         234  CALL_FUNCTION_0       0  ''
         236  COMPARE_OP               '!='
         238  POP_JUMP_IF_FALSE   304  'to 304'

 444     242  LOAD_GLOBAL              'os'
         244  LOAD_ATTR                'path'
         246  LOAD_ATTR                'dirname'
         248  LOAD_FAST                'realpath'
         250  CALL_FUNCTION_1       1  ''
         252  STORE_FAST               'module_dir'

 445     254  LOAD_GLOBAL              '_jython_aware_splitext'

 446     256  LOAD_GLOBAL              'os'
         258  LOAD_ATTR                'path'
         260  LOAD_ATTR                'basename'
         262  LOAD_FAST                'full_path'
         264  CALL_FUNCTION_1       1  ''
         266  CALL_FUNCTION_1       1  ''
         268  STORE_FAST               'mod_name'

 447     270  LOAD_GLOBAL              'os'
         272  LOAD_ATTR                'path'
         274  LOAD_ATTR                'dirname'
         276  LOAD_FAST                'full_path'
         278  CALL_FUNCTION_1       1  ''
         280  STORE_FAST               'expected_dir'

 448     282  LOAD_CONST               '%r module incorrectly imported from %r. Expected %r. Is this module globally installed?'
         284  STORE_FAST               'msg'

 450     286  LOAD_GLOBAL              'ImportError'

 451     288  LOAD_FAST                'msg'
         290  LOAD_FAST                'mod_name'
         292  LOAD_FAST                'module_dir'
         294  LOAD_FAST                'expected_dir'
         296  BUILD_TUPLE_3         3  ''
         298  BINARY_MODULO    
         300  CALL_FUNCTION_1       1  ''
         302  RAISE_VARARGS_1       1  ''
       304_0  COME_FROM           238  '238'

 452     304  LOAD_FAST                'self'
         306  LOAD_ATTR                'loadTestsFromModule'
         308  LOAD_FAST                'module'
         310  LOAD_FAST                'pattern'
         312  LOAD_CONST               ('pattern',)
         314  CALL_FUNCTION_KW_2     2  ''
         316  LOAD_CONST            0  False
         318  BUILD_TUPLE_2         2  ''
         320  RETURN_VALUE     
       322_0  COME_FROM           128  '128'
         322  JUMP_FORWARD        588  'to 588'
         326  ELSE                     '588'

 453     326  LOAD_GLOBAL              'os'
         328  LOAD_ATTR                'path'
         330  LOAD_ATTR                'isdir'
         332  LOAD_FAST                'full_path'
         334  CALL_FUNCTION_1       1  ''
         336  POP_JUMP_IF_FALSE   584  'to 584'

 454     340  LOAD_FAST                'namespace'
         342  UNARY_NOT        
         344  POP_JUMP_IF_FALSE   378  'to 378'

 455     348  LOAD_GLOBAL              'os'
         350  LOAD_ATTR                'path'
         352  LOAD_ATTR                'isfile'
         354  LOAD_GLOBAL              'os'
         356  LOAD_ATTR                'path'
         358  LOAD_ATTR                'join'
         360  LOAD_FAST                'full_path'
         362  LOAD_CONST               '__init__.py'
         364  CALL_FUNCTION_2       2  ''
         366  CALL_FUNCTION_1       1  ''
         368  UNARY_NOT        
         370  POP_JUMP_IF_FALSE   378  'to 378'

 456     374  LOAD_CONST               (None, False)
         376  RETURN_END_IF    

 458     378  LOAD_CONST               None
         380  STORE_FAST               'load_tests'

 459     382  LOAD_CONST               None
         384  STORE_FAST               'tests'

 460     386  LOAD_FAST                'self'
         388  LOAD_ATTR                '_get_name_from_path'
         390  LOAD_FAST                'full_path'
         392  CALL_FUNCTION_1       1  ''
         394  STORE_FAST               'name'

 461     396  SETUP_EXCEPT        412  'to 412'

 462     398  LOAD_FAST                'self'
         400  LOAD_ATTR                '_get_module_from_name'
         402  LOAD_FAST                'name'
         404  CALL_FUNCTION_1       1  ''
         406  STORE_FAST               'package'
         408  POP_BLOCK        
         410  JUMP_FORWARD        502  'to 502'
       412_0  COME_FROM_EXCEPT    396  '396'

 463     412  DUP_TOP          
         414  LOAD_GLOBAL              'case'
         416  LOAD_ATTR                'SkipTest'
         418  COMPARE_OP               'exception-match'
         420  POP_JUMP_IF_FALSE   460  'to 460'
         424  POP_TOP          
         426  STORE_FAST               'e'
         428  POP_TOP          
         430  SETUP_FINALLY       450  'to 450'

 464     432  LOAD_GLOBAL              '_make_skipped_test'
         434  LOAD_FAST                'name'
         436  LOAD_FAST                'e'
         438  LOAD_FAST                'self'
         440  LOAD_ATTR                'suiteClass'
         442  CALL_FUNCTION_3       3  ''
         444  LOAD_CONST            0  False
         446  BUILD_TUPLE_2         2  ''
         448  RETURN_VALUE     
       450_0  COME_FROM_FINALLY   430  '430'
         450  LOAD_CONST               None
         452  STORE_FAST               'e'
         454  DELETE_FAST              'e'
         456  END_FINALLY      
         458  JUMP_FORWARD        582  'to 582'

 465     460  POP_TOP          
         462  POP_TOP          
         464  POP_TOP          

 467     466  LOAD_GLOBAL              '_make_failed_import_test'
         468  LOAD_FAST                'name'
         470  LOAD_FAST                'self'
         472  LOAD_ATTR                'suiteClass'
         474  CALL_FUNCTION_2       2  ''
         476  UNPACK_SEQUENCE_2     2  ''
         478  STORE_FAST               'error_case'
         480  STORE_FAST               'error_message'

 468     482  LOAD_FAST                'self'
         484  LOAD_ATTR                'errors'
         486  LOAD_ATTR                'append'
         488  LOAD_FAST                'error_message'
         490  CALL_FUNCTION_1       1  ''
         492  POP_TOP          

 469     494  LOAD_FAST                'error_case'
         496  LOAD_CONST            0  False
         498  BUILD_TUPLE_2         2  ''
         500  RETURN_VALUE     
       502_0  COME_FROM           410  '410'

 471     502  LOAD_GLOBAL              'getattr'
         504  LOAD_FAST                'package'
         506  LOAD_CONST               'load_tests'
         508  LOAD_CONST               None
         510  CALL_FUNCTION_3       3  ''
         512  STORE_FAST               'load_tests'

 473     514  LOAD_FAST                'self'
         516  LOAD_ATTR                '_loading_packages'
         518  LOAD_ATTR                'add'
         520  LOAD_FAST                'name'
         522  CALL_FUNCTION_1       1  ''
         524  POP_TOP          

 474     526  SETUP_FINALLY       568  'to 568'

 475     528  LOAD_FAST                'self'
         530  LOAD_ATTR                'loadTestsFromModule'
         532  LOAD_FAST                'package'
         534  LOAD_FAST                'pattern'
         536  LOAD_CONST               ('pattern',)
         538  CALL_FUNCTION_KW_2     2  ''
         540  STORE_FAST               'tests'

 476     542  LOAD_FAST                'load_tests'
         544  LOAD_CONST               None
         546  COMPARE_OP               'is-not'
         548  POP_JUMP_IF_FALSE   560  'to 560'

 478     552  LOAD_FAST                'tests'
         554  LOAD_CONST            0  False
         556  BUILD_TUPLE_2         2  ''
         558  RETURN_END_IF    

 479     560  LOAD_FAST                'tests'
         562  LOAD_CONST            1  True
         564  BUILD_TUPLE_2         2  ''
         566  RETURN_VALUE     
       568_0  COME_FROM_FINALLY   526  '526'

 481     568  LOAD_FAST                'self'
         570  LOAD_ATTR                '_loading_packages'
         572  LOAD_ATTR                'discard'
         574  LOAD_FAST                'name'
         576  CALL_FUNCTION_1       1  ''
         578  POP_TOP          
         580  END_FINALLY      
       582_0  COME_FROM           458  '458'
         582  JUMP_FORWARD        588  'to 588'

 483     584  LOAD_CONST               (None, False)
         586  RETURN_VALUE     
       588_0  COME_FROM           582  '582'
       588_1  COME_FROM           322  '322'

Parse error at or near `COME_FROM' instruction at offset 172_0


defaultTestLoader = TestLoader()

def _makeLoader(prefix, sortUsing, suiteClass=None):
    loader = TestLoader()
    loader.sortTestMethodsUsing = sortUsing
    loader.testMethodPrefix = prefix
    if suiteClass:
        loader.suiteClass = suiteClass
    return loader


def getTestCaseNames(testCaseClass, prefix, sortUsing=util.three_way_cmp):
    return _makeLoader(prefix, sortUsing).getTestCaseNames(testCaseClass)


def makeSuite(testCaseClass, prefix='test', sortUsing=util.three_way_cmp, suiteClass=suite.TestSuite):
    return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromTestCase(testCaseClass)


def findTestCases(module, prefix='test', sortUsing=util.three_way_cmp, suiteClass=suite.TestSuite):
    return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromModule(module)